/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aybolit.core.objects.dao.impl;

import aybolit.core.objects.dao.BedsDao;
import aybolit.core.objects.model.Beds;
import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Masumov Emin
 */

@Transactional
public class BedsDaoImpl  implements BedsDao,Serializable{
 SessionFactory sessionFactory;
    @Transactional
    @Override
    public List<Beds> findBedsbyChamberId(String id) {
       return sessionFactory.getCurrentSession().getNamedQuery("Beds.findAllBedsByChamberId").setParameter("ch_id",Integer.parseInt(id)).list();     
    }
   @Resource(name = "sessionFactory")
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public List<Beds> findFreeBedsbyChamberId(String id) {
        if(id==null)id="0";
       return sessionFactory.getCurrentSession().getNamedQuery("Beds.findAllFreeBedsByChamberId").setParameter("ch_id",Integer.parseInt(id)).setParameter("status", 15).list();     

    }

    @Override
    public void changeBedStatus(Beds beds) {
        sessionFactory.getCurrentSession().saveOrUpdate(beds);
    }

    @Override
    public Beds findBedsById(String id) {
        Beds b=(Beds)sessionFactory.getCurrentSession().getNamedQuery("Beds.findAllBedsById").setParameter("id", Integer.parseInt(id)).uniqueResult();
        return b;
    }
}
